package close.kenny.shell.view
{
	import close.kenny.shell.ShellFacade;
	import close.kenny.shell.model.vo.UserVO;
	import close.kenny.shell.view.ui.Login;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.events.FlexEvent;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	public class LoginMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "LoginMediator";
		public function LoginMediator(viewComponent:Login)
		{
			super(NAME, viewComponent);
		}
		private function get login():Login
		{
			return viewComponent as Login;
		}
		override public function onRegister():void
		{
			login.loginButton.addEventListener(MouseEvent.CLICK,loginButtonHandle);
			login.username.addEventListener(FlexEvent.ENTER,loginTextHandle);
			login.password.addEventListener(FlexEvent.ENTER,loginTextHandle);
		}
		override public function onRemove():void
		{
			login.loginButton.removeEventListener(MouseEvent.CLICK,loginButtonHandle);
			login.username.removeEventListener(FlexEvent.ENTER,loginTextHandle);
			login.password.removeEventListener(FlexEvent.ENTER,loginTextHandle);
		}
		private function loginButtonHandle(event:MouseEvent):void
		{
			loginHandle();
		}
		private function loginTextHandle(event:FlexEvent):void
		{
			loginHandle();
		}
		public function loginHandle():void
		{
			var user:UserVO=new UserVO();
			user.code=login.username.text;
			user.pwd=login.password.text;
			sendNotification(ShellFacade.LOGIN,user);
		}
	}
}